﻿'Namespace AnalysisTechniques
'    Public Class AutoTrend
'#Const MANY_OPTIONS = True
'#Region "AnalysisTechnique Inherited Code"
'        Inherits AnalysisTechnique
'        Public Sub New(ByVal chart As Chart)
'            MyBase.New(chart) ' Call the base class constructor.
'            Description = "Main AutoTrend analysis technique."
'            Name = "AutoTrend"
'            If chart IsNot Nothing Then AddHandler chart.ChartKeyDown, AddressOf KeyPress
'        End Sub
'#End Region

'        Friend Overrides Sub OnCreate()
'            MyBase.OnCreate()
'            If Chart IsNot Nothing Then
'                RV = Chart.Settings("RangeValue").Value * 2.5
'                SwingRV = Chart.Settings("RangeValue").Value * 1.5
'                DecimalPlaces = 2
'                FineRVIncrementValue = Chart.GetMinTick
'                CoarseRVIncrementValue = Chart.GetMinTick * 5
'            End If
'        End Sub

'        Private bcLengths As New List(Of Double)

'        Protected Sub KeyPress(ByVal sender As Object, ByVal e As KeyEventArgs)
'            If Chart IsNot Nothing AndAlso IsEnabled Then
'                Dim key As Key
'                If e.SystemKey = key.None Then
'                    key = e.Key
'                Else
'                    key = e.SystemKey
'                End If
'                If Keyboard.Modifiers = ModifierKeys.None Then
'                    If key = IncrementRVUpFineAmount Then
'                        RV += FineRVIncrementValue
'                        Chart.ReApplyAnalysisTechnique(Me)
'                    ElseIf key = IncrementRVDownFineAmount And RV >= FineRVIncrementValue Then
'                        RV -= FineRVIncrementValue
'                        Chart.ReApplyAnalysisTechnique(Me)
'                    ElseIf key = IncrementRVUpCoarseAmount Then
'                        RV += CoarseRVIncrementValue
'                        Chart.ReApplyAnalysisTechnique(Me)
'                    ElseIf key = IncrementRVDownCoarseAmount And RV >= CoarseRVIncrementValue Then
'                        RV -= CoarseRVIncrementValue
'                        Chart.ReApplyAnalysisTechnique(Me)
'                    ElseIf key = SetRVToBaseRV Then
'                        RV = Chart.Settings("RangeValue").Value * 2.5
'                        Chart.ReApplyAnalysisTechnique(Me)
'                    ElseIf key = SetRVToNextBCLength Then
'                        For i = channelLines.Count - 1 To 0 Step -1
'                            Dim channelLine As ChannelLine = channelLines(i)
'                            If channelLine.IsConfirmed And Not channelLine.IsCancelled Then
'                                bcLengths.Add(RV)
'                                If RV = Round(Abs(CurrentSwing.StartPrice - CurrentSwing.EndPrice), 5) Then
'                                    RV = Round(Abs(CurrentSwing.StartPrice - CurrentSwing.EndPrice) + Chart.GetMinTick, 5)
'                                ElseIf Round(Abs(CurrentSwing.StartPrice - CurrentSwing.EndPrice), 5) < Round(Abs(channelLine.BCSwingLine.EndPoint.Y - channelLine.BCSwingLine.StartPoint.Y), 5) Then
'                                    RV = Round(Abs(CurrentSwing.StartPrice - CurrentSwing.EndPrice), 5)
'                                ElseIf RV = Round(Abs(channelLine.BCSwingLine.EndPoint.Y - channelLine.BCSwingLine.StartPoint.Y), 5) Then
'                                    RV = Round(Abs(channelLine.BCSwingLine.EndPoint.Y - channelLine.BCSwingLine.StartPoint.Y) + Chart.GetMinTick, 5)
'                                Else
'                                    RV = Round(Abs((channelLine.BCSwingLine.EndPoint.Y - channelLine.BCSwingLine.StartPoint.Y)), 5)
'                                End If
'                                Chart.ReApplyAnalysisTechnique(Me)
'                                Exit For
'                            End If
'                        Next
'                    ElseIf key = SetRVToPreviousBCLength Then
'                        If bcLengths.Count > 0 Then
'                            RV = bcLengths(bcLengths.Count - 1)
'                            bcLengths.RemoveAt(bcLengths.Count - 1)
'                            Chart.ReApplyAnalysisTechnique(Me)
'                            'ElseIf bcLengths.Count > 1 Then
'                            '    RV = bcLengths(bcLengths.Count - 2)
'                            '    bcLengths.RemoveAt(bcLengths.Count - 1)
'                            '    bcLengths.RemoveAt(bcLengths.Count - 1)
'                            '    Chart.ReApplyAnalysisTechnique(Me)
'                        End If
'#If HOTKEYS Then
'            ElseIf name.Length = 2 Or name.Length = 3 AndAlso name.Substring(0, 1) = "F" Then
'                Try
'                    Dim value As Decimal
'                    If Keyboard.Modifiers = ModifierKeys.None Then
'                        value = Me.GetType.GetProperty(name).GetValue(Me, Nothing)
'                    ElseIf Keyboard.Modifiers = ModifierKeys.Alt Then
'                        value = Me.GetType.GetProperty("Alt" & name).GetValue(Me, Nothing)
'                    ElseIf Keyboard.Modifiers = ModifierKeys.Control Then
'                        value = Me.GetType.GetProperty("Ctrl" & name).GetValue(Me, Nothing)
'                    ElseIf Keyboard.Modifiers = ModifierKeys.Shift Then
'                        value = Me.GetType.GetProperty("Shift" & name).GetValue(Me, Nothing)
'                    End If
'                    If value <> 0 Then
'                        RV = value
'                        Chart.ReApplyAnalysisTechnique(Me)
'                    End If
'                Catch

'                End Try
'#End If
'                    End If
'                End If
'            End If
'        End Sub

'        Protected Class Swing
'            Protected _tl As TrendLine
'            Public ReadOnly Property TL As TrendLine
'                Get
'                    Return _tl
'                End Get
'            End Property
'            Public Property Direction As Direction
'            Public Sub New(ByVal tl As TrendLine, ByVal direction As Direction)
'                _tl = tl
'                StartBar = tl.StartPoint.X
'                StartPrice = tl.StartPoint.Y
'                EndBar = tl.EndPoint.X
'                EndPrice = tl.EndPoint.Y
'                Me.Direction = direction
'            End Sub
'            Public Property StartBar As Integer
'                Get
'                    Return TL.StartPoint.X
'                End Get
'                Set(ByVal value As Integer)
'                    TL.StartPoint = New Point(value, TL.StartPoint.Y)
'                End Set
'            End Property
'            Public Property StartPrice As Decimal
'                Get
'                    Return TL.StartPoint.Y
'                End Get
'                Set(ByVal value As Decimal)
'                    TL.StartPoint = New Point(TL.StartPoint.X, value)
'                End Set
'            End Property
'            Public Property EndBar As Integer
'                Get
'                    Return TL.EndPoint.X
'                End Get
'                Set(ByVal value As Integer)
'                    TL.EndPoint = New Point(value, TL.EndPoint.Y)
'                End Set
'            End Property
'            Public Property EndPrice As Decimal
'                Get
'                    Return TL.EndPoint.Y
'                End Get
'                Set(ByVal value As Decimal)
'                    TL.EndPoint = New Point(TL.EndPoint.X, value)
'                End Set
'            End Property
'            Public Property ChannelLine As ChannelLine
'            Public Shared Operator =(ByVal swing1 As Swing, ByVal swing2 As Swing) As Boolean
'                Return swing1 Is swing2
'            End Operator
'            Public Shared Operator <>(ByVal swing1 As Swing, ByVal swing2 As Swing) As Boolean
'                Return swing1 IsNot swing2
'            End Operator
'        End Class
'        Protected Class ChannelLine
'            Public Sub New(ByVal tl As TrendLine)
'                Base = tl
'            End Sub
'            Public Property Base As TrendLine
'            Public Property PriceToConfirm As Decimal
'            Public Property ExtendPrice As Decimal
'            Public Property PriceToCancel As Decimal
'            Public Property IsCancelled As Boolean
'            Public Property IsConfirmed As Boolean
'            Public Property CanExtend As Boolean = True
'            Public Property Direction As Direction
'            Public Property PivotSwing As Swing
'            Public Property BCSwingLine As TrendLine
'            Public Property BCLengthText As Label
'            Public Property TargetText As Label
'            Public Property IsCut As Boolean
'            Public Property IsGapped As Boolean
'            Public Property BCSwingMatched As Boolean
'            Public Property IsBackedUp As Boolean
'            Public Property CutBarNumber As Integer = -1
'            Public Property APoint As Point
'            Public Property BPoint As Point
'            Public Property CPoint As Point
'        End Class
'        Protected Class SwingChannelLine
'            Public Sub New(ByVal tl As TrendLine)
'                Base = tl
'            End Sub
'            Public Property Base As TrendLine
'            Public Property BCSwingLine As TrendLine
'            Public Property IsActive As Boolean
'            Public Property IsConfirmed As Boolean
'            Public Property APoint As Point
'            Public Property BPoint As Point
'            Public Property CPoint As Point
'        End Class
'        Protected Structure GapMarker
'            Public Property Line As TrendLine
'            Public Property Swing As Swing
'            Public Property State As GapMarkerState
'        End Structure
'        Public Enum GapMarkerState
'            Inactive
'            FollowsRVPoint
'            FollowsExtension
'        End Enum
'        Public Enum Direction
'            Up = -1
'            Down = 0
'        End Enum

'#Region "Inputs"

'        <Input("The reversal value.")> Public Property RV As Decimal = 2
'        '<Input("The base RV.")> Public Property BaseRV As Decimal = 2
'        <Input("The reversal value for the swing channel.")> Public Property SwingRV As Decimal
'        '<Input("The dollar equivalent of the symbol minimum move.")> Public Property SymbolPriceMinimumMove As Decimal = 25

'#If MANY_OPTIONS Then
'        '<Input("The number of decimal places shown on all labels.")>
'        Public Property DecimalPlaces As Integer = 2
'#Else
'        Public Property DecimalPlaces As Integer = 2
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for swing lines.", "Swing Lines")>
'        Public Property SwingLineNeutralColor As Color = Colors.LightGray
'#Else
'        Public Property SwingLineNeutralColor As Color = Colors.LightGray
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for swing lines during an up trend.")>
'        Public Property SwingLineUpTrendColor As Color = ColorConverter.ConvertFromString("#FF00BF00")
'#Else
'        Public Property SwingLineUpTrendColor As Color = ColorConverter.ConvertFromString("#FF00BF00")
'#End If

'#If MANY_OPTIONS Then
'        <Input("The color for swing lines during a down trend.")>
'        Public Property SwingLineDownTrendColor As Color = ColorConverter.ConvertFromString("#FFBF0000")
'#Else
'        Public Property SwingLineDownTrendColor As Color = ColorConverter.ConvertFromString("#FFBF0000")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The visibility for swing lines.", "Visibility Switches")>
'        Public Property SwingLinesVisible As Boolean = True
'#Else
'        Public Property SwingLinesVisible As Boolean = True
'#End If
'#If MANY_OPTIONS Then
'        <Input("The visibility for all swing channel lines.")>
'        Public Property SwingChannelLinesVisible As Boolean = True
'#Else
'        Public Property SwingChannelLinesVisible As Boolean = True
'#End If
'#If MANY_OPTIONS Then
'        <Input("The visibility for all channel lines.")>
'        Public Property ChannelLinesVisible As Boolean = True
'#Else
'        Public Property ChannelLinesVisible As Boolean = True
'#End If
'        <Input("The option to hide all potential channel lines except the last one in each direction.")> Public Property ShowOnlyLastPotentialChannels As Boolean = True
'        <Input("The option to hide all confirmed channel lines except the last one in each direction.")> Public Property ShowOnlyLastConfirmedChannels As Boolean = True
'#If MANY_OPTIONS Then
'        <Input("The visibility for confirmed history channel lines.")>
'        Public Property ConfirmedHistoryChannelLinesVisible As Boolean = False
'#Else
'        Public Property ConfirmedHistoryChannelLinesVisible As Boolean = False
'#End If
'#If MANY_OPTIONS Then
'        <Input("The visibility for potential history channel lines.")>
'        Public Property PotentialHistoryChannelLinesVisible As Boolean = False
'#Else
'        Public Property PotentialHistoryChannelLinesVisible As Boolean = False
'#End If
'#If MANY_OPTIONS Then
'        <Input("The visibility for potential and confirmed history channel line parallels.")>
'        Public Property HistoryChannelLineParallelsVisible As Boolean = False
'#Else
'        Public Property HistoryChannelLineParallelsVisible As Boolean = True
'#End If
'#If MANY_OPTIONS Then
'        <Input("The visibility for BC length texts.")>
'        Public Property BCLengthTextsVisible As Boolean = True
'#Else
'        Public Property BCLengthTextsVisible As Boolean = True
'#End If
'#If MANY_OPTIONS Then
'        <Input("The visibility for BC target texts.")>
'        Public Property BCTargetTextsVisible As Boolean = True
'#Else
'        Public Property BCTargetTextsVisible As Boolean = True
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for up gap markers.", "Gap Markers")>
'        Public Property UpGapMarkerColor As Color = Colors.LightGreen
'#Else
'        Public Property UpGapMarkerColor As Color = Colors.LightGreen
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for down gap markers.")>
'        Public Property DownGapMarkerColor As Color = Colors.Pink
'#Else
'        Public Property DownGapMarkerColor As Color = Colors.Pink
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for potential up channel lines.", "Channel Lines")>
'        Public Property PotentialUpChannelLineColor As Color = ColorConverter.ConvertFromString("#FF005000")
'#Else
'        Public Property PotentialUpChannelLineColor As Color = ColorConverter.ConvertFromString("#FF005000")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for potential down channel lines.")>
'        Public Property PotentialDownChannelLineColor As Color = ColorConverter.ConvertFromString("#FF550000")
'#Else
'        Public Property PotentialDownChannelLineColor As Color = ColorConverter.ConvertFromString("#FF550000")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for confirmed up channel lines.")>
'        Public Property ConfirmedUpChannelLineColor As Color = Colors.Lime
'#Else
'        Public Property ConfirmedUpChannelLineColor As Color = Colors.Lime
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for confirmed down channel lines.")>
'        Public Property ConfirmedDownChannelLineColor As Color = Colors.Red
'#Else
'        Public Property ConfirmedDownChannelLineColor As Color = Colors.Red
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for backed up confirmed up channel lines.")>
'        Public Property BackedUpConfirmedUpChannelLineColor As Color = Colors.DarkGreen
'#Else
'        Public Property BackedUpConfirmedUpChannelLineColor As Color = Colors.DarkGreen
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for backed up confirmed down channel lines.")>
'        Public Property BackedUpConfirmedDownChannelLineColor As Color = Colors.DarkRed
'#Else
'        Public Property BackedUpConfirmedDownChannelLineColor As Color = Colors.DarkRed
'#End If
'        '#If MANY_OPTIONS Then
'        '        <Input("The color for backed up potential up channel lines.")>
'        '        Public Property BackedUpPotentialUpChannelLineColor As Color = Colors.DarkMagenta
'        '#Else
'        '        Public Property BackedUpPotentialUpChannelLineColor As Color = Colors.DarkMagenta
'        '#End If
'        '#If MANY_OPTIONS Then
'        '        <Input("The color for backed up potential down channel lines.")>
'        '        Public Property BackedUpPotentialDownChannelLineColor As Color = Colors.DarkGoldenrod
'        '#Else
'        '        Public Property BackedUpPotentialDownChannelLineColor As Color = Colors.DarkGoldenrod
'        '#End If
'#If MANY_OPTIONS Then
'        <Input("The color for potential up channel lines that have been hit.")>
'        Public Property PotentialHistoryUpChannelLineColor As Color = ColorConverter.ConvertFromString("#FF404000")
'#Else
'        Public Property PotentialHistoryUpChannelLineColor As Color = ColorConverter.ConvertFromString("#FF404000")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for potential down channel lines that have been hit.")>
'        Public Property PotentialHistoryDownChannelLineColor As Color = ColorConverter.ConvertFromString("#FF002B55")
'#Else
'        Public Property PotentialHistoryDownChannelLineColor As Color = ColorConverter.ConvertFromString("#FF002B55")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for confirmed up channel lines that have been hit.")>
'        Public Property ConfirmedHistoryUpChannelLineColor As Color = ColorConverter.ConvertFromString("#FF008500")
'#Else
'        Public Property ConfirmedHistoryUpChannelLineColor As Color = ColorConverter.ConvertFromString("#FF008500")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for confirmed down channel lines that have been hit.")>
'        Public Property ConfirmedHistoryDownChannelLineColor As Color = ColorConverter.ConvertFromString("#FFB40000")
'#Else
'        Public Property ConfirmedHistoryDownChannelLineColor As Color = ColorConverter.ConvertFromString("#FFB40000")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for gapped up channel lines.")>
'        Public Property GappedUpChannelLineColor As Color = Colors.Purple
'#Else
'        Public Property GappedUpChannelLineColor As Color = Colors.Purple
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for gapped down channel lines.")>
'        Public Property GappedDownChannelLineColor As Color = Colors.Purple
'#Else
'        Public Property GappedDownChannelLineColor As Color = Colors.Purple
'#End If
'#If MANY_OPTIONS Then
'        <Input("The option to enable or disable bar coloring.", "Bar Coloring")>
'        Public Property ColorBars As Boolean = True
'#Else
'        Public Property ColorBars As Boolean = True
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for the bars during a neutral trend direction state.")>
'        Public Property NeutralBarColor As Color = Colors.Gray
'#Else
'        Public Property NeutralBarColor As Color = Colors.Gray
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for the bars during an up trend.")>
'        Public Property UpTrendBarColor As Color = ColorConverter.ConvertFromString("#FF006A00")
'#Else
'        Public Property UpTrendBarColor As Color = ColorConverter.ConvertFromString("#FF006A00")
'#End If
'#If MANY_OPTIONS Then
'        <Input("The color for the bars during a down trend.")>
'        Public Property DownTrendBarColor As Color = ColorConverter.ConvertFromString("#FF6A0000")
'#Else
'        Public Property DownTrendBarColor As Color = ColorConverter.ConvertFromString("#FF6A0000")
'#End If
'        <Input("The fine adjustment for the RV.", "Hotkeys")> Public Property FineRVIncrementValue As Decimal = 0.5
'        <Input("The course adjustment for the RV.")> Public Property CoarseRVIncrementValue As Decimal = 0.5
'        '#If MANY_OPTIONS Then
'        '<Input("The hotkey to snap to the base RV.")>
'        'Public Property SnapToBaseRV As Key = Key.F4
'        '#Else
'        '        Public Property SnapToBaseRV As Key = Key.F4
'        '#End If
'        '#If MANY_OPTIONS Then
'        <Input("The hotkey to increment the RV up the specified fine amount.")>
'        Public Property IncrementRVUpFineAmount As Key = Key.F8
'        '#Else
'        '        Public Property IncrementRVUpFineAmount As Key = Key.F8
'        '#End If
'        '#If MANY_OPTIONS Then
'        <Input("The hotkey to increment the RV down the specified fine amount.")>
'        Public Property IncrementRVDownFineAmount As Key = Key.F7
'        '#Else
'        '       Public Property IncrementRVDownFineAmount As Key = Key.F7
'        '#End If
'        '#If MANY_OPTIONS Then
'        <Input("The hotkey to increment the RV up the specified coarse amount.")>
'        Public Property IncrementRVUpCoarseAmount As Key = Key.F6
'        '#Else
'        '        Public Property IncrementRVUpCoarseAmount As Key = Key.F6
'        '#End If
'        '#If MANY_OPTIONS Then
'        <Input("The hotkey to increment the RV down the specified coarse amount.")>
'        Public Property IncrementRVDownCoarseAmount As Key = Key.F5
'        '#Else
'        '        Public Property IncrementRVDownCoarseAmount As Key = Key.F5
'        '#End If
'        <Input()> Public Property SetRVToBaseRV As Key = Key.F3
'        <Input()> Public Property SetRVToNextBCLength As Key = Key.F2
'        <Input()> Public Property SetRVToPreviousBCLength As Key = Key.F1

'#If HOTKEYS Then
'        <Input("", "RV Assigners")> Public Property F1 As Decimal
'        <Input()> Public Property F2 As Decimal
'        <Input()> Public Property F3 As Decimal
'        <Input()> Public Property F4 As Decimal
'        <Input()> Public Property F5 As Decimal
'        <Input()> Public Property F6 As Decimal
'        <Input()> Public Property F7 As Decimal
'        <Input()> Public Property F8 As Decimal
'        <Input()> Public Property F9 As Decimal
'        <Input()> Public Property F10 As Decimal
'        <Input()> Public Property F11 As Decimal
'        <Input()> Public Property F12 As Decimal
'        <Input()> Public Property CtrlF1 As Decimal
'        <Input()> Public Property CtrlF2 As Decimal
'        <Input()> Public Property CtrlF3 As Decimal
'        <Input()> Public Property CtrlF4 As Decimal
'        <Input()> Public Property CtrlF5 As Decimal
'        <Input()> Public Property CtrlF6 As Decimal
'        <Input()> Public Property CtrlF7 As Decimal
'        <Input()> Public Property CtrlF8 As Decimal
'        <Input()> Public Property CtrlF9 As Decimal
'        <Input()> Public Property CtrlF10 As Decimal
'        <Input()> Public Property CtrlF11 As Decimal
'        <Input()> Public Property CtrlF12 As Decimal
'        <Input()> Public Property ShiftF1 As Decimal
'        <Input()> Public Property ShiftF2 As Decimal
'        <Input()> Public Property ShiftF3 As Decimal
'        <Input()> Public Property ShiftF4 As Decimal
'        <Input()> Public Property ShiftF5 As Decimal
'        <Input()> Public Property ShiftF6 As Decimal
'        <Input()> Public Property ShiftF7 As Decimal
'        <Input()> Public Property ShiftF8 As Decimal
'        <Input()> Public Property ShiftF9 As Decimal
'        <Input()> Public Property ShiftF10 As Decimal
'        <Input()> Public Property ShiftF11 As Decimal
'        <Input()> Public Property ShiftF12 As Decimal
'        <Input()> Public Property AltF1 As Decimal
'        <Input()> Public Property AltF2 As Decimal
'        <Input()> Public Property AltF3 As Decimal
'        <Input()> Public Property AltF4 As Decimal
'        <Input()> Public Property AltF5 As Decimal
'        <Input()> Public Property AltF6 As Decimal
'        <Input()> Public Property AltF7 As Decimal
'        <Input()> Public Property AltF8 As Decimal
'        <Input()> Public Property AltF9 As Decimal
'        <Input()> Public Property AltF10 As Decimal
'        <Input()> Public Property AltF11 As Decimal
'        <Input()> Public Property AltF12 As Decimal
'#End If

'#End Region
'        Protected Event NewSwingUp()
'        Protected Event NewSwingDown()
'        Protected Event UpSwingExtension()
'        Protected Event DownSwingExtension()

'        Private rvText As Label
'        Private rvProLine As TrendLine
'        Private swings As List(Of Swing)
'        Private channelLines As New List(Of ChannelLine)
'        Private backedUpChannelLines As New List(Of ChannelLine)
'        Protected ReadOnly Property CurrentSwing As Swing
'            <DebuggerStepThrough()>
'            Get
'                If swings.Count = 0 Then
'                    Return New Swing(New TrendLine, Direction.Up)
'                Else
'                    Return swings(swings.Count - 1)
'                End If
'            End Get
'        End Property
'        Protected ReadOnly Property CurrentSwing(ByVal swingsBack As Integer) As Swing
'            <DebuggerStepThrough()>
'            Get
'                Return swings(swings.Count - 1 - swingsBack)
'            End Get
'        End Property
'        Protected ReadOnly Property CurrentChannelLine As ChannelLine
'            <DebuggerStepThrough()>
'            Get
'                Return channelLines(channelLines.Count - 1)
'            End Get
'        End Property
'        Protected swingChannel As SwingChannelLine
'        Private currentGapMark As GapMarker
'        Private barColorsDirty As Boolean
'        Public Overrides Sub Reset()
'            MyBase.Reset()
'            If ColorBars Or barColorsDirty Then
'                BarColor(0, Chart.bars.Count - 1, Chart.Settings("Bar Color").Value, SwingLineNeutralColor)
'                barColorsDirty = False
'            End If
'        End Sub

'        Private Function NewChannelTrendline(ByVal color As Color, ByVal startPoint As Point, ByVal endPoint As Point, Optional ByVal addToChart As Boolean = True) As TrendLine
'            Return MyBase.NewTrendLine(color, startPoint, endPoint, addToChart) ' If(addToChart And Min(startPoint.X, endPoint.X) >= Chart.Bounds.X1, True, False))
'        End Function
'        Private Sub AddChannelTrendlineToChart(ByVal trendLine As TrendLine)
'            If trendLine IsNot Nothing Then
'                If Min(trendLine.StartPoint.X, trendLine.EndPoint.X) >= Chart.Bounds.X1 Then
'                    MyBase.AddObjectToChart(trendLine)
'                End If
'            End If
'        End Sub
'        Private Sub SetEndPoint(ByVal trendline As TrendLine, ByVal point As Point)
'            If trendline IsNot Nothing Then
'                If Min(trendline.StartPoint.X, point.X) >= Chart.Bounds.X1 Then
'                    trendline.EndPoint = point
'                Else
'                    MyBase.RemoveObjectFromChart(trendline)
'                End If
'            End If
'        End Sub
'        Private Sub SetStartPoint(ByVal trendline As TrendLine, ByVal point As Point)
'            If trendline IsNot Nothing Then
'                If Min(point.X, trendline.EndPoint.X) >= Chart.Bounds.X1 Then
'                    trendline.StartPoint = point
'                Else
'                    MyBase.RemoveObjectFromChart(trendline)
'                End If
'            End If
'        End Sub
'        Protected Overrides Sub Begin()
'            channelLines = New List(Of ChannelLine)
'            backedUpChannelLines = New List(Of ChannelLine)
'            swings = New List(Of Swing)
'            swings.Add(New Swing(NewTrendline(SwingLineNeutralColor, New Point(CurrentBar.Number, CurrentBar.Close), New Point(CurrentBar.Number, CurrentBar.Close), SwingLinesVisible), Direction.Down))
'            rvText = NewLabel("", Colors.White, New Point(0, 0), True)
'            rvText.VerticalAlignment = LabelVerticalAlignment.Center
'            rvProLine = NewTrendline(SwingLineNeutralColor, New Point(0, 0), New Point(0, 0))
'            rvProLine.Pen.DashStyle = TrendLineDashStyle
'            swingChannel = New SwingChannelLine(NewTrendline(SwingLineNeutralColor, New Point(0, 0), New Point(0, 0), True))

'            'SwingRV = Chart.Settings("RangeValue").Value * 1.5

'        End Sub
'        Protected Overrides Sub Main()
'            'For Each channel In channelLines
'            '    If Min(channel.Base.StartPoint.X, channel.Base.EndPoint.X) >= Chart.Bounds.X1 Then

'            '    End If
'            'Next
'            If ColorBars Then
'                CType(Chart.bars(CurrentBar.Number - 1).Pen.Brush, SolidColorBrush).Color = NeutralBarColor
'                RefreshObject(Chart.bars(CurrentBar.Number - 1))
'                barColorsDirty = True
'            End If
'            If CurrentBar.High - CurrentSwing.EndPrice >= RV AndAlso CurrentBar.Number <> CurrentSwing.EndBar AndAlso CurrentSwing.Direction = Direction.Down Then
'                'new swing up
'                swings.Add(New Swing(NewTrendLine(SwingLineNeutralColor, New Point(CurrentSwing.EndBar, CurrentSwing.EndPrice), New Point(CurrentBar.Number, CurrentBar.High), SwingLinesVisible), Direction.Up))
'                CheckChannelLinesForCancelOrConfirm()
'                DrawDownChannel()
'                CheckDownChannelsCanExtend()
'                CheckChannelLinesForExtensions()
'                RemoveSwingChannel()
'                NewSwingGapMark()
'                RaiseEvent NewSwingUp()
'            ElseIf CurrentSwing.EndPrice - CurrentBar.Low >= RV AndAlso CurrentBar.Number <> CurrentSwing.EndBar AndAlso CurrentSwing.Direction = Direction.Up Then
'                ' new swing down
'                swings.Add(New Swing(NewTrendLine(SwingLineNeutralColor, New Point(CurrentSwing.EndBar, CurrentSwing.EndPrice), New Point(CurrentBar.Number, CurrentBar.Low), SwingLinesVisible), Direction.Down))
'                CheckChannelLinesForCancelOrConfirm()
'                DrawUpChannel()
'                CheckUpChannelsCanExtend()
'                CheckChannelLinesForExtensions()
'                RemoveSwingChannel()
'                NewSwingGapMark()
'                RaiseEvent NewSwingDown()
'            ElseIf CurrentBar.High >= CurrentSwing.EndPrice And CurrentSwing.Direction = Direction.Up And swings.Count > 0 Then
'                ' extension up
'                CurrentSwing.EndBar = CurrentBar.Number
'                CurrentSwing.EndPrice = CurrentBar.High
'                CheckChannelLinesForCancelOrConfirm()
'                DrawDownChannel()
'                CheckDownChannelsCanExtend()
'                CheckChannelLinesForExtensions()
'                RaiseEvent UpSwingExtension()
'            ElseIf CurrentBar.Low <= CurrentSwing.EndPrice And CurrentSwing.Direction = Direction.Down And swings.Count > 0 Then
'                ' extension down
'                CurrentSwing.EndBar = CurrentBar.Number
'                CurrentSwing.EndPrice = CurrentBar.Low
'                CheckChannelLinesForCancelOrConfirm()
'                DrawUpChannel()
'                CheckUpChannelsCanExtend()
'                CheckChannelLinesForExtensions()
'                RaiseEvent DownSwingExtension()
'            End If
'            If swings.Count > 0 And SwingChannelLinesVisible Then ProcessSwingChannel(CurrentSwing)
'            DrawRVTextAndProjectionLine()
'            If swings.Count > 2 Then ProcessCurrentGapMark()
'        End Sub
'        Private Sub ProcessCurrentGapMark()
'            Dim p As Double = CurrentBar.Close
'            If CurrentSwing.Direction = Direction.Up Then
'                If p > CurrentSwing(2).EndPrice + RV Then ' if gap is being created
'                    If currentGapMark.Swing IsNot CurrentSwing Then ' if new gap
'                        currentGapMark.Swing = CurrentSwing
'                        currentGapMark.Line = NewTrendline(UpGapMarkerColor, New Point(0, 0), New Point(0, 0), True)
'                        currentGapMark.Line.Pen.Thickness = 3
'                        currentGapMark.State = GapMarkerState.FollowsRVPoint
'                    End If
'                    currentGapMark.Line.StartPoint = New Point(LinCalc(CurrentSwing.StartPrice, CurrentSwing.StartBar, CurrentSwing.EndPrice, CurrentSwing.EndBar, CurrentSwing(2).EndPrice), CurrentSwing(2).EndPrice)
'                End If
'            Else
'                If p < CurrentSwing(2).EndPrice - RV Then ' if gap is being created
'                    If currentGapMark.Swing IsNot CurrentSwing Then ' if new gap
'                        currentGapMark.Swing = CurrentSwing
'                        currentGapMark.Line = NewTrendline(DownGapMarkerColor, New Point(0, 0), New Point(0, 0), True)
'                        currentGapMark.Line.Pen.Thickness = 3
'                        currentGapMark.State = GapMarkerState.FollowsRVPoint
'                    End If
'                    currentGapMark.Line.StartPoint = New Point(LinCalc(CurrentSwing.StartPrice, CurrentSwing.StartBar, CurrentSwing.EndPrice, CurrentSwing.EndBar, CurrentSwing(2).EndPrice), CurrentSwing(2).EndPrice)
'                End If
'            End If
'            If currentGapMark.Swing Is CurrentSwing(1) Then
'                If (currentGapMark.Swing.Direction = Direction.Up And p <= currentGapMark.Line.StartPoint.Y) Or
'                    (currentGapMark.Swing.Direction = Direction.Down And p >= currentGapMark.Line.StartPoint.Y) Then
'                    currentGapMark.Swing = Nothing
'                    RemoveObjectFromChart(currentGapMark.Line)
'                    currentGapMark.Line = Nothing
'                    currentGapMark.State = GapMarkerState.Inactive
'                End If
'            End If
'            If currentGapMark.State = GapMarkerState.FollowsRVPoint Then
'                If currentGapMark.Swing.Direction = Direction.Up Then
'                    currentGapMark.Line.EndPoint = New Point(LinCalc(currentGapMark.Swing.StartPrice, currentGapMark.Swing.StartBar, currentGapMark.Swing.EndPrice, currentGapMark.Swing.EndBar, currentGapMark.Swing.EndPrice - RV), currentGapMark.Swing.EndPrice - RV)
'                Else
'                    currentGapMark.Line.EndPoint = New Point(LinCalc(currentGapMark.Swing.StartPrice, currentGapMark.Swing.StartBar, currentGapMark.Swing.EndPrice, currentGapMark.Swing.EndBar, currentGapMark.Swing.EndPrice + RV), currentGapMark.Swing.EndPrice + RV)
'                End If
'            ElseIf currentGapMark.State = GapMarkerState.FollowsExtension Then
'                currentGapMark.Line.EndPoint = New Point(LinCalc(currentGapMark.Swing.StartPrice, currentGapMark.Swing.StartBar, currentGapMark.Swing.EndPrice, currentGapMark.Swing.EndBar, CurrentSwing.EndPrice), CurrentSwing.EndPrice)
'            End If
'        End Sub
'        Private Sub NewSwingGapMark()
'            If swings.Count > 1 AndAlso currentGapMark.Swing Is CurrentSwing(1) Then currentGapMark.State = GapMarkerState.FollowsExtension
'            If swings.Count > 2 AndAlso currentGapMark.Swing Is CurrentSwing(2) Then currentGapMark.State = GapMarkerState.Inactive
'        End Sub

'        Protected Sub ProcessSwingChannel(ByVal swing As Swing)
'            If swing.Direction = Direction.Down And swings.Count > 0 Then
'                If Not swingChannel.IsActive Then
'                    Dim highBar As New Point
'                    Dim lowBar As New Point(0, Double.MaxValue)
'                    Dim bPoint As Point, cPoint As Point, rvMatched As Boolean
'                    For i = swing.StartBar - 1 To CurrentBar.Number - 1
'                        If Bars(i).Low < lowBar.Y Then
'                            lowBar = New Point(i + 1, Bars(i).Low)
'                            highBar = New Point(0, 0)
'                        End If
'                        If Bars(i).High > highBar.Y Then highBar = New Point(i + 1, Bars(i).High)
'                        If highBar.Y - lowBar.Y >= SwingRV Then
'                            bPoint = lowBar
'                            cPoint = highBar
'                            rvMatched = True
'                        End If
'                    Next
'                    If rvMatched Then
'                        With swingChannel
'                            .IsActive = True
'                            .APoint = swing.TL.StartPoint
'                            .BPoint = bPoint
'                            .CPoint = cPoint
'                            .Base = NewTrendline(SwingLineNeutralColor, swing.TL.StartPoint, cPoint)
'                            .Base.HasParallel = True
'                            .Base.ParallelDistance = .BPoint.Y - LinCalc(.APoint.X, .APoint.Y, .CPoint.X, .CPoint.Y, .BPoint.X)
'                            .Base.ExtendRight = True
'                        End With
'                    End If
'                End If
'                If swingChannel.IsActive And Not swingChannel.IsConfirmed Then
'                    Dim lowBar As New Point(0, Double.MaxValue)
'                    Dim highBar As New Point
'                    For i = swingChannel.CPoint.X - 1 To CurrentBar.Number - 1
'                        If Bars(i).Low <= lowBar.Y Then lowBar = New Point(i + 1, Bars(i).Low)
'                        If Bars(i).High >= highBar.Y Then highBar = New Point(i + 1, Bars(i).High)
'                    Next
'                    If highBar.Y >= swingChannel.CPoint.Y Then
'                        With swingChannel
'                            .CPoint = highBar
'                            .Base.EndPoint = highBar
'                            .Base.ParallelDistance = .BPoint.Y - LinCalc(.APoint.X, .APoint.Y, .CPoint.X, .CPoint.Y, .BPoint.X)
'                        End With
'                    End If
'                    If lowBar.Y < swingChannel.BPoint.Y Then
'                        swingChannel.IsConfirmed = True
'                        swingChannel.BCSwingLine = NewTrendline(SwingLineNeutralColor, swingChannel.BPoint, swingChannel.CPoint, False)
'                    End If
'                End If
'                If swingChannel.IsConfirmed Then
'                    Dim highBar As Point
'                    For i = swing.EndBar - 1 To CurrentBar.Number - 1
'                        If Bars(i).High > highBar.Y Then highBar = New Point(i + 1, Bars(i).High)
'                    Next
'                    If highBar.Y - swing.EndPrice >= Abs(swingChannel.BCSwingLine.EndPoint.Y - swingChannel.BCSwingLine.StartPoint.Y) Then
'                        With swingChannel
'                            .IsConfirmed = False
'                            .CPoint = highBar
'                            .BPoint = New Point(swing.EndBar, swing.EndPrice)
'                            .Base.EndPoint = highBar
'                            .Base.ParallelDistance = .BPoint.Y - LinCalc(.APoint.X, .APoint.Y, .CPoint.X, .CPoint.Y, .BPoint.X)
'                            'RemoveObjectFromChart(.BCSwingLine)
'                        End With
'                    End If
'                End If
'            Else
'                ' up
'                If Not swingChannel.IsActive Then
'                    Dim highBar As New Point
'                    Dim lowBar As New Point(0, Double.MaxValue)
'                    Dim bPoint As Point, cPoint As Point, rvMatched As Boolean
'                    For i = swing.StartBar - 1 To CurrentBar.Number - 1
'                        If Bars(i).High > highBar.Y Then
'                            highBar = New Point(i + 1, Bars(i).High)
'                            lowBar = New Point(0, Double.MaxValue)
'                        End If
'                        If Bars(i).Low < lowBar.Y Then lowBar = New Point(i + 1, Bars(i).Low)
'                        If highBar.Y - lowBar.Y >= SwingRV Then
'                            bPoint = highBar
'                            cPoint = lowBar
'                            rvMatched = True
'                        End If
'                    Next
'                    If rvMatched Then
'                        With swingChannel
'                            .IsActive = True
'                            .APoint = swing.TL.StartPoint
'                            .BPoint = bPoint
'                            .CPoint = cPoint
'                            .Base = NewTrendline(SwingLineNeutralColor, swing.TL.StartPoint, cPoint)
'                            .Base.HasParallel = True
'                            .Base.ParallelDistance = .BPoint.Y - LinCalc(.APoint.X, .APoint.Y, .CPoint.X, .CPoint.Y, .BPoint.X)
'                            .Base.ExtendRight = True
'                        End With
'                    End If
'                End If
'                If swingChannel.IsActive And Not swingChannel.IsConfirmed Then
'                    Dim lowBar As New Point(0, Double.MaxValue)
'                    Dim highBar As New Point
'                    For i = swingChannel.CPoint.X - 1 To CurrentBar.Number - 1
'                        If Bars(i).Low <= lowBar.Y Then lowBar = New Point(i + 1, Bars(i).Low)
'                        If Bars(i).High >= highBar.Y Then highBar = New Point(i + 1, Bars(i).High)
'                    Next
'                    If lowBar.Y <= swingChannel.CPoint.Y Then
'                        With swingChannel
'                            .CPoint = lowBar
'                            .Base.EndPoint = lowBar
'                            .Base.ParallelDistance = .BPoint.Y - LinCalc(.APoint.X, .APoint.Y, .CPoint.X, .CPoint.Y, .BPoint.X)
'                        End With
'                    End If
'                    If highBar.Y > swingChannel.BPoint.Y Then
'                        swingChannel.IsConfirmed = True
'                        swingChannel.BCSwingLine = NewTrendline(SwingLineNeutralColor, swingChannel.BPoint, swingChannel.CPoint, False)
'                    End If
'                End If
'                If swingChannel.IsConfirmed Then
'                    Dim lowBar As New Point(0, Double.MaxValue)
'                    For i = swing.EndBar - 1 To CurrentBar.Number - 1
'                        If Bars(i).Low < lowBar.Y Then lowBar = New Point(i + 1, Bars(i).Low)
'                    Next
'                    If swing.EndPrice - lowBar.Y >= Abs(swingChannel.BCSwingLine.EndPoint.Y - swingChannel.BCSwingLine.StartPoint.Y) Then
'                        With swingChannel
'                            .IsConfirmed = False
'                            .CPoint = lowBar
'                            .BPoint = New Point(swing.EndBar, swing.EndPrice)
'                            .Base.EndPoint = lowBar
'                            .Base.ParallelDistance = .BPoint.Y - LinCalc(.APoint.X, .APoint.Y, .CPoint.X, .CPoint.Y, .BPoint.X)
'                            'RemoveObjectFromChart(.BCSwingLine)
'                        End With
'                    End If
'                End If
'            End If
'        End Sub
'        Protected Sub RemoveSwingChannel()
'            RemoveObjectFromChart(swingChannel.Base)
'            'RemoveObjectFromChart(swingChannel.Parallel)
'            RemoveObjectFromChart(swingChannel.BCSwingLine)
'            swingChannel.IsActive = False
'            swingChannel.IsConfirmed = False
'        End Sub

'        Protected Function GetDollarValue(ByVal priceDif As Decimal) As Decimal
'            Dim multiplier As Double
'            If Chart.Settings("UseRandom").Value Then
'                multiplier = 1
'            Else
'                If Chart.IB.Contract(Chart.TickerID).Multiplier = "" OrElse Not IsNumeric(Chart.IB.Contract(Chart.TickerID).Multiplier) Then
'                    multiplier = 1
'                Else
'                    multiplier = Chart.IB.Contract(Chart.TickerID).Multiplier
'                End If
'            End If
'            Dim shares As Integer = Chart.Settings("DefaultOrderQuantity").Value
'            'Dim a = priceDif / Chart.GetMinTick * Chart.GetMinTick * multiplier * shares
'            Return priceDif * multiplier * shares
'        End Function

'        Public Overrides Property Name As String

'        Protected Sub DrawRVTextAndProjectionLine()
'            Try
'                If swings.Count >= 5 Then

'                    Dim averageCount As Integer = 4
'                    Dim averageAngleCount As Double = 0
'                    For i = swings.Count - 1 To swings.Count - averageCount Step -1
'                        'ShowInfoBox("opposite with " & i & ": " & Abs(swings(i).TL.EndPoint.Y - swings(i).TL.StartPoint.Y))
'                        'ShowInfoBox("adjacent with " & i & ": " & Abs(swings(i).TL.EndPoint.X - swings(i).TL.StartPoint.X))
'                        averageAngleCount += Atan(Abs(swings(i).TL.EndPoint.Y - swings(i).TL.StartPoint.Y) / Abs(swings(i).TL.EndPoint.X - swings(i).TL.StartPoint.X)) * (180 / PI)
'                    Next
'                    'ShowInfoBox("we got past the angle calculation!")
'                    Dim angle As Double = averageAngleCount / averageCount
'                    'ShowInfoBox("we got past the averaging!")
'                    rvProLine.StartPoint = New Point(CurrentSwing.EndBar, CurrentSwing.EndPrice)
'                    'ShowInfoBox("angle is: " & angle)
'                    Dim barSkip As Integer
'                    If Chart.Settings("IsSlaveChart").Value Then
'                        barSkip = 1
'                    Else
'                        If CurrentSwing.Direction = Direction.Up Then
'                            barSkip = Abs(CurrentBar.Close - (CurrentSwing.EndPrice - RV)) / Chart.Settings("RangeValue").Value * 2
'                        Else
'                            barSkip = Abs(CurrentBar.Close - (CurrentSwing.EndPrice + RV)) / Chart.Settings("RangeValue").Value * 2
'                        End If
'                    End If

'                    Dim endBar As Integer = Max(CurrentSwing.EndBar + Round(RV / Tan(angle / (180 / PI)), 0), CurrentBar.Number + barSkip)
'                    'ShowInfoBox("we got past the end bar calculation!")
'                    If CurrentSwing.Direction = Direction.Up Then
'                        rvProLine.EndPoint = New Point(endBar, CurrentSwing.EndPrice - RV)
'                        rvText.Location = New Point(endBar, CurrentSwing.EndPrice - RV)
'                    Else
'                        rvProLine.EndPoint = New Point(endBar, CurrentSwing.EndPrice + RV)
'                        rvText.Location = New Point(endBar, CurrentSwing.EndPrice + RV)
'                    End If
'                    angle = Atan(Abs(rvProLine.EndPoint.Y - rvProLine.StartPoint.Y) / Abs(rvProLine.EndPoint.X - rvProLine.StartPoint.X))
'                    For Each channelLine In channelLines
'                        If channelLine.TargetText IsNot Nothing Then
'                            'If CurrentSwing.Direction = Direction.Up Then
'                            'Log("line at bar " & channelLine.TargetText.Location.X & ": " & CurrentSwing.EndBar + Round(Abs(channelLine.TargetText.Location.Y - CurrentBar.Close) / Tan(angle), 0))
'                            channelLine.TargetText.Location = New Point(CurrentBar.Number + Round(Abs(channelLine.TargetText.Location.Y - CurrentBar.Close) / Tan(angle), 0), channelLine.TargetText.Location.Y)
'                            'Else
'                            '    channelLine.TargetText.Location = New Point(CurrentSwing.EndBar - Round(Abs(channelLine.TargetText.Location.Y - CurrentSwing.EndPrice) / Tan(angle), 0), channelLine.TargetText.Location.Y)
'                            'End If
'                        End If
'                    Next

'                Else
'                    If CurrentSwing.Direction = Direction.Up Then
'                        rvText.Location = New Point(CurrentBar.Number, CurrentSwing.EndPrice - RV)
'                    Else
'                        rvText.Location = New Point(CurrentBar.Number, CurrentSwing.EndPrice + RV)
'                    End If
'                End If
'                rvText.Text = "- " & FormatNumber(GetDollarValue(RV), DecimalPlaces)
'            Catch ex As Exception
'                ShowInfoBox("There was an error in the projection RV line calculation: " & ex.Message, Chart.DesktopWindow)
'            End Try
'        End Sub

'        Protected Sub DrawDownChannel()
'            If swings.Count >= 2 Then
'                Dim aPoint As Point, bPoint As Point, cPoint As Point = New Point(CurrentSwing.EndBar, CurrentSwing.EndPrice)
'                Dim highPoint As Double, highBar As Integer, lowPoint As Double, lowBar As Integer
'                lowPoint = Decimal.MaxValue
'                ' find B-point
'                For i = swings.Count - 1 To 0 Step -1
'                    If swings(i).StartPrice < lowPoint Then
'                        lowBar = swings(i).StartBar
'                        lowPoint = swings(i).StartPrice
'                    End If
'                    If swings(i).StartPrice > CurrentSwing.EndPrice Then Exit For
'                Next
'                bPoint = New Point(lowBar, lowPoint)
'                ' find A-point 
'                Dim heightToMatch As Decimal = CurrentSwing.EndPrice - bPoint.Y
'                highPoint = Decimal.MinValue
'                lowPoint = Decimal.MaxValue
'                For i = swings.Count - 2 To 0 Step -1
'                    If swings(i).StartPrice > highPoint Then
'                        highBar = swings(i).StartBar
'                        highPoint = swings(i).StartPrice
'                        lowPoint = Decimal.MaxValue
'                    Else
'                        lowPoint = Min(lowPoint, swings(i).StartPrice)
'                    End If
'                    If highPoint - lowPoint > heightToMatch Or i = 0 Then
'                        aPoint = New Point(highBar, highPoint)
'                        Exit For
'                    End If
'                Next
'                If aPoint.Y > cPoint.Y Then
'                    If CurrentSwing.ChannelLine Is Nothing Then
'                        If ShowOnlyLastPotentialChannels Then
'                            For Each channel In channelLines
'                                If Not channel.IsConfirmed And channel.Direction = Direction.Down And Not channel.IsCut Then
'                                    'Dim pen = channel.Base.Pen
'                                    'pen.Brush = New SolidColorBrush(BackedUpPotentialDownChannelLineColor)
'                                    'channel.Base.Pen = pen
'                                    RemoveObjectFromChart(channel.Base)
'                                    channel.IsBackedUp = True
'                                End If
'                            Next
'                        End If
'                        channelLines.Add(New ChannelLine(NewChannelTrendline(PotentialDownChannelLineColor, New Point(0, 0), New Point(CurrentSwing.EndBar, CurrentSwing.EndPrice), ChannelLinesVisible)))
'                        CurrentChannelLine.Base.ExtendRight = True
'                        CurrentChannelLine.Base.HasParallel = True
'                        CurrentChannelLine.Direction = Direction.Down
'                        CurrentChannelLine.PivotSwing = CurrentSwing
'                        CurrentChannelLine.BCLengthText = NewLabel(FormatNumber(GetDollarValue(cPoint.Y - bPoint.Y), DecimalPlaces, TriState.True), PotentialDownChannelLineColor, AddToX(cPoint, -2), BCLengthTextsVisible)
'                        CurrentChannelLine.BCLengthText.HorizontalAlignment = LabelHorizontalAlignment.Right
'                        CurrentChannelLine.BCLengthText.VerticalAlignment = LabelVerticalAlignment.Bottom
'                        CurrentSwing.ChannelLine = CurrentChannelLine
'                    End If
'                    With CurrentChannelLine
'                        .BCLengthText.Text = FormatNumber(GetDollarValue(cPoint.Y - bPoint.Y), DecimalPlaces)
'                        .BCLengthText.Location = AddToX(cPoint, -2)
'                        .Base.ParallelDistance = bPoint.Y - LinCalc(aPoint.X, aPoint.Y, cPoint.X, cPoint.Y, bPoint.X)
'                        SetStartPoint(CurrentSwing.ChannelLine.Base, aPoint)
'                        SetEndPoint(CurrentSwing.ChannelLine.Base, cPoint)
'                        .PriceToCancel = aPoint.Y
'                        .PriceToConfirm = bPoint.Y
'                        .ExtendPrice = bPoint.Y
'                        .APoint = aPoint
'                        .BPoint = bPoint
'                        .CPoint = cPoint
'                        DrawDownBCTargetTexts(bPoint)
'                    End With
'                End If '
'                CheckDownChannelsForHit(bPoint, cPoint)
'                SetDownChannelsToHistory(bPoint, cPoint)
'                RefreshUpChannelsPriceToCancel()
'            End If
'        End Sub
'        Protected Sub DrawUpChannel()
'            If swings.Count >= 2 Then
'                Dim aPoint As Point, bPoint As Point, cPoint As Point = New Point(CurrentSwing.EndBar, CurrentSwing.EndPrice)
'                Dim highPoint As Decimal, highBar As Integer, lowPoint As Decimal, lowBar As Integer
'                highPoint = Decimal.MinValue
'                ' find B-point
'                For i = swings.Count - 1 To 0 Step -1
'                    If swings(i).StartPrice > highPoint Then
'                        highBar = swings(i).StartBar
'                        highPoint = swings(i).StartPrice
'                    End If
'                    If swings(i).StartPrice < CurrentSwing.EndPrice Then Exit For
'                Next
'                bPoint = New Point(highBar, highPoint)
'                ' find A-point 
'                Dim heightToMatch As Decimal = bPoint.Y - CurrentSwing.EndPrice
'                highPoint = Decimal.MinValue
'                lowPoint = Decimal.MaxValue
'                For i = swings.Count - 2 To 0 Step -1
'                    If swings(i).StartPrice < lowPoint Then
'                        lowBar = swings(i).StartBar
'                        lowPoint = swings(i).StartPrice
'                        highPoint = Decimal.MinValue
'                    Else
'                        highPoint = Max(highPoint, swings(i).StartPrice)
'                    End If
'                    If highPoint <> Decimal.MinValue AndAlso highPoint - lowPoint > heightToMatch Or i = 0 Then
'                        aPoint = New Point(lowBar, lowPoint)
'                        Exit For
'                    End If
'                Next
'                If aPoint.Y < cPoint.Y Then
'                    If CurrentSwing.ChannelLine Is Nothing Then
'                        If ShowOnlyLastPotentialChannels Then
'                            For Each channel In channelLines
'                                If Not channel.IsConfirmed And channel.Direction = Direction.Up And Not channel.IsCut Then
'                                    'Dim pen = channel.Base.Pen
'                                    'pen.Brush = New SolidColorBrush(BackedUpPotentialUpChannelLineColor)
'                                    'channel.Base.Pen = pen
'                                    RemoveObjectFromChart(channel.Base)
'                                    channel.IsBackedUp = True
'                                End If
'                            Next
'                        End If
'                        channelLines.Add(New ChannelLine(NewChannelTrendline(PotentialUpChannelLineColor, New Point(0, 0), New Point(CurrentSwing.EndBar, CurrentSwing.EndPrice), ChannelLinesVisible)))
'                        CurrentChannelLine.Base.ExtendRight = True
'                        CurrentChannelLine.Base.HasParallel = True
'                        CurrentChannelLine.Direction = Direction.Up
'                        CurrentChannelLine.PivotSwing = CurrentSwing
'                        CurrentChannelLine.BCLengthText = NewLabel(FormatNumber(GetDollarValue(bPoint.Y - cPoint.Y), DecimalPlaces, TriState.True), PotentialUpChannelLineColor, AddToX(cPoint, -2), BCLengthTextsVisible)
'                        CurrentChannelLine.BCLengthText.HorizontalAlignment = LabelHorizontalAlignment.Right
'                        CurrentChannelLine.BCLengthText.VerticalAlignment = LabelVerticalAlignment.Top
'                        CurrentSwing.ChannelLine = CurrentChannelLine
'                    End If
'                    With CurrentChannelLine
'                        .BCLengthText.Text = FormatNumber(GetDollarValue(bPoint.Y - cPoint.Y), DecimalPlaces, TriState.True)
'                        .BCLengthText.Location = AddToX(cPoint, -2)
'                        .Base.ParallelDistance = bPoint.Y - LinCalc(aPoint.X, aPoint.Y, cPoint.X, cPoint.Y, bPoint.X)
'                        SetStartPoint(CurrentSwing.ChannelLine.Base, aPoint)
'                        SetEndPoint(CurrentSwing.ChannelLine.Base, cPoint)
'                        .PriceToCancel = aPoint.Y
'                        .PriceToConfirm = bPoint.Y
'                        .ExtendPrice = bPoint.Y
'                        .APoint = aPoint
'                        .BPoint = bPoint
'                        .CPoint = cPoint
'                    End With
'                    DrawUpBCTargetTexts(bPoint)
'                End If
'                CheckUpChannelsForHit(bPoint, cPoint)
'                SetUpChannelsToHistory(bPoint, cPoint)
'                RefreshDownChannelsPriceToCancel()
'            End If
'        End Sub

'        Protected Sub DrawDownBCTargetTexts(ByVal bPoint As Point)
'            For Each channelLine In channelLines
'                With channelLine
'                    If .Direction = Direction.Down And .BCSwingMatched = False Then
'                        Dim length As Decimal = .CPoint.Y - .BPoint.Y
'                        'If .TargetText Is Nothing Then .TargetText = NewLabel("----" & FormatNumber(GetDollarValue(length), DecimalPlaces), ConfirmedUpChannelLineColor, New Point(Chart.RelativeRightMarginLocation, bPoint.Y - length))
'                        '.TargetText.Text = "----" & FormatNumber(GetDollarValue(length), DecimalPlaces)
'                        '.TargetText.Location = New Point(Chart.RelativeRightMarginLocation, bPoint.Y + length + .TargetText.RelativeHeight / 2)
'                    End If
'                End With
'            Next
'        End Sub
'        Protected Sub DrawUpBCTargetTexts(ByVal bPoint As Point)
'            For Each channelLine In channelLines
'                With channelLine
'                    If .Direction = Direction.Up And .BCSwingMatched = False Then
'                        Dim length As Decimal = .BPoint.Y - .CPoint.Y
'                        'If .TargetText Is Nothing Then .TargetText = NewLabel("----" & FormatNumber(GetDollarValue(length), DecimalPlaces), ConfirmedUpChannelLineColor, New Point(Chart.RelativeRightMarginLocation, bPoint.Y - length))
'                        '.TargetText.Text = "----" & FormatNumber(GetDollarValue(length), DecimalPlaces)
'                        '.TargetText.Location = New Point(Chart.RelativeRightMarginLocation, bPoint.Y - length + .TargetText.RelativeHeight / 2)
'                    End If
'                End With
'            Next
'        End Sub

'        Protected Sub CheckDownChannelsForHit(ByVal bPoint As Point, ByVal cPoint As Point)
'            For Each channelLine In channelLines
'                If channelLine.CutBarNumber = -1 And channelLine.IsCut = False Then
'                    If channelLine.Direction = Direction.Down AndAlso channelLine.PivotSwing IsNot CurrentSwing AndAlso CurrentBar.High >= LinCalc(channelLine.Base.StartPoint.X, channelLine.Base.StartPoint.Y, channelLine.Base.EndPoint.X, channelLine.Base.EndPoint.Y, CurrentBar.Number) Then
'                        If cPoint.Y - bPoint.Y >= channelLine.CPoint.Y - channelLine.BPoint.Y Then channelLine.BCSwingMatched = True
'                        channelLine.CutBarNumber = CurrentBar.Number
'                    End If
'                Else
'                    If channelLine.Direction = Direction.Up And channelLine.BCSwingMatched = False Then channelLine.CutBarNumber = -1
'                End If
'            Next
'        End Sub
'        Protected Sub CheckUpChannelsForHit(ByVal bPoint As Point, ByVal cPoint As Point)
'            For Each channelLine In channelLines
'                If channelLine.IsCut = False Then
'                    If channelLine.CutBarNumber = -1 Then
'                        If channelLine.Direction = Direction.Up AndAlso channelLine.PivotSwing IsNot CurrentSwing AndAlso CurrentBar.Low <= LinCalc(channelLine.Base.StartPoint.X, channelLine.Base.StartPoint.Y, channelLine.Base.EndPoint.X, channelLine.Base.EndPoint.Y, CurrentBar.Number) Then
'                            If bPoint.Y - cPoint.Y >= channelLine.BPoint.Y - channelLine.CPoint.Y Then channelLine.BCSwingMatched = True
'                            channelLine.CutBarNumber = CurrentBar.Number
'                        End If
'                    Else
'                        If channelLine.Direction = Direction.Down And channelLine.BCSwingMatched = False Then channelLine.CutBarNumber = -1
'                    End If
'                End If
'            Next
'        End Sub

'        Protected Sub SetDownChannelsToHistory(ByVal bPoint As Point, ByVal cPoint As Point)
'            For Each channelLine In channelLines
'                If channelLine.IsCut = False Then
'                    If channelLine.Direction = Direction.Down Then
'                        If cPoint.Y - bPoint.Y >= channelLine.CPoint.Y - channelLine.BPoint.Y Then
'                            If channelLine.CutBarNumber <> -1 Then
'                                With channelLine.Base
'                                    If channelLine.IsConfirmed Then
'                                        ' historify down channel
'                                        ShowLastConfirmedChannelLine(Direction.Down)
'                                        channelLine.IsCut = True
'                                        .Pen.DashStyle = TrendLineDashStyle
'                                        .Pen.Brush = New SolidColorBrush(ConfirmedHistoryDownChannelLineColor)
'                                        .Pen.Thickness = 1
'                                        SetEndPoint(channelLine.Base, New Point(channelLine.CutBarNumber, LinCalc(.StartPoint.X, .StartPoint.Y, .EndPoint.X, .EndPoint.Y, channelLine.CutBarNumber)))
'                                        .ExtendRight = False
'                                        channelLine.IsBackedUp = False
'                                        If ConfirmedHistoryChannelLinesVisible Then
'                                            AddChannelTrendlineToChart(channelLine.Base)
'                                            'AddObjectToChart(channelLine.Parallel)
'                                        Else
'                                            RemoveObjectFromChart(channelLine.Base)
'                                            'RemoveObjectFromChart(channelLine.Parallel)
'                                        End If
'                                        If Not channelLine.IsGapped Then
'                                            If Not HistoryChannelLineParallelsVisible And .HasParallel Then
'                                                If .HasParallel Then
'                                                    .HasParallel = False
'                                                End If
'                                            ElseIf HistoryChannelLineParallelsVisible And .HasParallel = False Then
'                                                .HasParallel = True
'                                                .ParallelDistance = channelLine.BPoint.Y - LinCalc(channelLine.APoint.X, channelLine.APoint.Y, channelLine.CPoint.X, channelLine.CPoint.Y, channelLine.BPoint.X)
'                                            End If
'                                            If Not ConfirmedHistoryChannelLinesVisible Then RemoveObjectFromChart(channelLine.Base)
'                                        End If
'                                        RefreshObject(channelLine.Base)
'                                        RemoveObjectFromChart(channelLine.BCLengthText)
'                                    Else
'                                        ' historify potential down
'                                        channelLine.IsCut = True
'                                        .Pen.DashStyle = TrendLineDashStyle
'                                        .Pen.Brush = New SolidColorBrush(PotentialHistoryDownChannelLineColor)
'                                        SetEndPoint(channelLine.Base, New Point(channelLine.CutBarNumber, LinCalc(.StartPoint.X, .StartPoint.Y, .EndPoint.X, .EndPoint.Y, channelLine.CutBarNumber)))
'                                        .ExtendRight = False
'                                        channelLine.IsBackedUp = False
'                                        If PotentialHistoryChannelLinesVisible Then
'                                            AddChannelTrendlineToChart(channelLine.Base)
'                                            'AddObjectToChart(channelLine.Parallel)
'                                        Else
'                                            RemoveObjectFromChart(channelLine.Base)
'                                            'RemoveObjectFromChart(channelLine.Parallel)
'                                        End If
'                                        If Not HistoryChannelLineParallelsVisible And .HasParallel Then
'                                            If .HasParallel Then
'                                                .HasParallel = False
'                                            End If
'                                        ElseIf HistoryChannelLineParallelsVisible And .HasParallel = False Then
'                                            .HasParallel = True
'                                            .ParallelDistance = channelLine.BPoint.Y - LinCalc(channelLine.APoint.X, channelLine.APoint.Y, channelLine.CPoint.X, channelLine.CPoint.Y, channelLine.BPoint.X)
'                                        End If ' 
'                                        If Not PotentialHistoryChannelLinesVisible Then RemoveObjectFromChart(channelLine.Base)
'                                        RefreshObject(channelLine.Base)
'                                        RemoveObjectFromChart(channelLine.BCLengthText)
'                                    End If
'                                End With
'                            Else
'                                If channelLine.IsConfirmed Then
'                                    'channelLine.Base.HasParallel = False
'                                    channelLine.IsGapped = True
'                                End If
'                            End If
'                            RemoveObjectFromChart(channelLine.BCSwingLine)
'                            RemoveObjectFromChart(channelLine.BCLengthText)
'                            RemoveObjectFromChart(channelLine.TargetText)
'                            'If channelLine.BCLengthText IsNot Nothing Then
'                            '    If HistoryBCTextsVisible Then
'                            '        channelLine.BCLengthText.Font.Brush = New SolidColorBrush(DownTrendBarColor)
'                            '        RefreshObject(channelLine.BCLengthText)
'                            '    Else
'                            '        RemoveObjectFromChart(channelLine.BCLengthText)
'                            '    End If
'                            'End If
'                        End If
'                    End If
'                End If
'            Next
'        End Sub
'        Protected Sub SetUpChannelsToHistory(ByVal bPoint As Point, ByVal cPoint As Point)
'            For Each channelLine In channelLines
'                If channelLine.IsCut = False Then
'                    If channelLine.Direction = Direction.Up Then
'                        If bPoint.Y - cPoint.Y >= channelLine.BPoint.Y - channelLine.CPoint.Y Then
'                            If channelLine.CutBarNumber <> -1 Then
'                                With channelLine.Base
'                                    If channelLine.IsConfirmed Then
'                                        ' historify up channel
'                                        ShowLastConfirmedChannelLine(Direction.Up)
'                                        channelLine.IsCut = True
'                                        .Pen.DashStyle = TrendLineDashStyle
'                                        .Pen.Brush = New SolidColorBrush(ConfirmedHistoryUpChannelLineColor)
'                                        SetEndPoint(channelLine.Base, New Point(channelLine.CutBarNumber, LinCalc(.StartPoint.X, .StartPoint.Y, .EndPoint.X, .EndPoint.Y, channelLine.CutBarNumber)))
'                                        .Pen.Thickness = 1
'                                        .ExtendRight = False
'                                        channelLine.IsBackedUp = False
'                                        If ConfirmedHistoryChannelLinesVisible Then
'                                            AddChannelTrendlineToChart(channelLine.Base)
'                                            'AddObjectToChart(channelLine.Parallel)
'                                        Else
'                                            RemoveObjectFromChart(channelLine.Base)
'                                            'RemoveObjectFromChart(channelLine.Parallel)
'                                        End If
'                                        If Not channelLine.IsGapped Then
'                                            If Not HistoryChannelLineParallelsVisible And .HasParallel Then
'                                                If .HasParallel Then
'                                                    .HasParallel = False
'                                                End If
'                                            ElseIf HistoryChannelLineParallelsVisible And .HasParallel = False Then
'                                                .HasParallel = True
'                                                .ParallelDistance = channelLine.BPoint.Y - LinCalc(channelLine.APoint.X, channelLine.APoint.Y, channelLine.CPoint.X, channelLine.CPoint.Y, channelLine.BPoint.X)
'                                            End If
'                                            If Not ConfirmedHistoryChannelLinesVisible Then RemoveObjectFromChart(channelLine.Base)
'                                        End If
'                                        RefreshObject(channelLine.Base)
'                                        RemoveObjectFromChart(channelLine.BCLengthText)
'                                    Else
'                                        ' historify potential up
'                                        channelLine.IsCut = True
'                                        .Pen.DashStyle = TrendLineDashStyle
'                                        .Pen.Brush = New SolidColorBrush(PotentialHistoryUpChannelLineColor)
'                                        SetEndPoint(channelLine.Base, New Point(channelLine.CutBarNumber, LinCalc(.StartPoint.X, .StartPoint.Y, .EndPoint.X, .EndPoint.Y, channelLine.CutBarNumber)))
'                                        .ExtendRight = False
'                                        channelLine.IsBackedUp = False
'                                        If PotentialHistoryChannelLinesVisible Then
'                                            AddChannelTrendlineToChart(channelLine.Base)
'                                            'AddObjectToChart(channelLine.Parallel)
'                                        Else
'                                            RemoveObjectFromChart(channelLine.Base)
'                                            'RemoveObjectFromChart(channelLine.Parallel)
'                                        End If
'                                        If Not HistoryChannelLineParallelsVisible And .HasParallel Then
'                                            If .HasParallel Then
'                                                .HasParallel = False
'                                            End If
'                                        ElseIf HistoryChannelLineParallelsVisible And .HasParallel = False Then
'                                            .HasParallel = True
'                                            .ParallelDistance = channelLine.BPoint.Y - LinCalc(channelLine.APoint.X, channelLine.APoint.Y, channelLine.CPoint.X, channelLine.CPoint.Y, channelLine.BPoint.X)
'                                        End If
'                                        If Not PotentialHistoryChannelLinesVisible Then RemoveObjectFromChart(channelLine.Base)
'                                        RefreshObject(channelLine.Base)
'                                        RemoveObjectFromChart(channelLine.BCLengthText)
'                                    End If
'                                End With
'                            Else
'                                If channelLine.IsConfirmed Then
'                                    'channelLine.Base.HasParallel = False
'                                    channelLine.IsGapped = True
'                                End If
'                            End If
'                            RemoveObjectFromChart(channelLine.BCSwingLine)
'                            RemoveObjectFromChart(channelLine.BCLengthText)
'                            RemoveObjectFromChart(channelLine.TargetText)
'                            'If channelLine.BCLengthText IsNot Nothing Then
'                            '    If HistoryBCTextsVisible Then
'                            '        channelLine.BCLengthText.Font.Brush = New SolidColorBrush(UpTrendBarColor)
'                            '        RefreshObject(channelLine.BCLengthText)
'                            '    Else
'                            '        RemoveObjectFromChart(channelLine.BCLengthText)
'                            '    End If
'                            'End If
'                        End If
'                    End If
'                End If
'            Next
'        End Sub

'        Protected Sub RefreshDownChannelsPriceToCancel()
'            For Each channelLine In channelLines
'                If channelLine.Direction = Direction.Down Then channelLine.PriceToCancel = channelLine.CPoint.Y
'            Next
'        End Sub
'        Protected Sub RefreshUpChannelsPriceToCancel()
'            For Each channelLine In channelLines
'                If channelLine.Direction = Direction.Up Then channelLine.PriceToCancel = channelLine.CPoint.Y
'            Next
'        End Sub

'        Protected Sub CutUpChannelLine(ByVal channelLine As ChannelLine)
'            With channelLine.Base
'                channelLine.IsCut = True
'                .Pen.DashStyle = TrendLineDashStyle
'                .Pen.Brush = New SolidColorBrush(PotentialHistoryUpChannelLineColor)
'                SetEndPoint(channelLine.Base, New Point(channelLine.CutBarNumber, LinCalc(.StartPoint.X, .StartPoint.Y, .EndPoint.X, .EndPoint.Y, channelLine.CutBarNumber)))
'                .ExtendRight = False
'                channelLine.IsBackedUp = False
'                If ConfirmedHistoryChannelLinesVisible Then AddChannelTrendlineToChart(channelLine.Base)
'                If Not HistoryChannelLineParallelsVisible And .HasParallel Then
'                    If .HasParallel Then
'                        .HasParallel = False
'                    End If
'                ElseIf HistoryChannelLineParallelsVisible And .HasParallel = False Then
'                    .HasParallel = True
'                    .ParallelDistance = channelLine.BPoint.Y - LinCalc(channelLine.APoint.X, channelLine.APoint.Y, channelLine.CPoint.X, channelLine.CPoint.Y, channelLine.BPoint.X)
'                End If
'                If Not PotentialHistoryChannelLinesVisible Then RemoveObjectFromChart(channelLine.Base)
'                RefreshObject(channelLine.Base)
'                RemoveObjectFromChart(channelLine.BCLengthText)
'            End With
'        End Sub
'        Protected Sub CutDownChannelLine(ByVal channelLine As ChannelLine)

'            With channelLine.Base
'                channelLine.IsCut = True
'                .Pen.DashStyle = TrendLineDashStyle
'                .Pen.Brush = New SolidColorBrush(PotentialHistoryDownChannelLineColor)
'                SetEndPoint(channelLine.Base, New Point(channelLine.CutBarNumber, LinCalc(.StartPoint.X, .StartPoint.Y, .EndPoint.X, .EndPoint.Y, channelLine.CutBarNumber)))
'                .ExtendRight = False
'                channelLine.IsBackedUp = False
'                If ConfirmedHistoryChannelLinesVisible Then AddChannelTrendlineToChart(channelLine.Base)
'                If Not HistoryChannelLineParallelsVisible And .HasParallel Then
'                    If .HasParallel Then
'                        .HasParallel = False
'                    End If
'                ElseIf HistoryChannelLineParallelsVisible And .HasParallel = False Then
'                    .HasParallel = True
'                    .ParallelDistance = channelLine.BPoint.Y - LinCalc(channelLine.APoint.X, channelLine.APoint.Y, channelLine.CPoint.X, channelLine.CPoint.Y, channelLine.BPoint.X)
'                End If
'                If Not PotentialHistoryChannelLinesVisible Then RemoveObjectFromChart(channelLine.Base)
'                RefreshObject(channelLine.Base)
'                RemoveObjectFromChart(channelLine.BCLengthText)
'            End With
'        End Sub

'        Protected Sub ConfirmUpChannelLine(ByVal channelLine As ChannelLine)
'            For Each channel In channelLines
'                If channel.Direction = Direction.Up AndAlso channel.IsGapped AndAlso channel.IsConfirmed AndAlso channel.IsCut = False Then
'                    If channel.IsBackedUp Then
'                        channel.IsBackedUp = False
'                    End If
'                    Dim pen = channel.Base.Pen
'                    pen.Brush = New SolidColorBrush(GappedUpChannelLineColor)
'                    channel.Base.Pen = pen
'                    channel.Base.HasParallel = False
'                End If
'            Next
'            With channelLine
'                If .IsBackedUp Then
'                    .IsBackedUp = False
'                    AddChannelTrendlineToChart(.Base)
'                    'ShowLastConfirmedChannelLine(Direction.Up)
'                End If
'                .IsConfirmed = True
'                Dim value As Decimal = .BPoint.Y - .CPoint.Y
'                .TargetText = NewLabel("- " & FormatNumber(GetDollarValue(value), DecimalPlaces), ConfirmedUpChannelLineColor, New Point(CurrentBar.Number, CurrentSwing.EndPrice - value), BCTargetTextsVisible)
'                .TargetText.VerticalAlignment = LabelVerticalAlignment.Center
'                .BCSwingLine = NewTrendline(ConfirmedUpChannelLineColor, .BPoint, .CPoint, ChannelLinesVisible)
'                .BCSwingLine.Pen.Thickness = 2
'                RemoveObjectFromChart(.BCLengthText)
'                .BCLengthText = NewLabel(FormatNumber(GetDollarValue(value), DecimalPlaces, TriState.True), ConfirmedUpChannelLineColor, AddToX(.CPoint, -2), BCLengthTextsVisible)
'                .BCLengthText.HorizontalAlignment = LabelHorizontalAlignment.Right
'                .BCLengthText.VerticalAlignment = LabelVerticalAlignment.Top
'                Dim pen = .Base.Pen
'                pen.Brush = New SolidColorBrush(ConfirmedUpChannelLineColor)
'                pen.Thickness = 2
'                .Base.Pen = pen
'                RefreshObject(.Base)
'                If ShowOnlyLastConfirmedChannels Then
'                    For Each channel In channelLines
'                        If channel.IsConfirmed And channel.Direction = Direction.Up And Not channel.IsGapped And Not channel.IsCut Then
'                            pen = channel.Base.Pen
'                            pen.Brush = New SolidColorBrush(BackedUpConfirmedUpChannelLineColor)
'                            pen.Thickness = 1
'                            channel.Base.Pen = pen
'                            pen = channel.BCSwingLine.Pen
'                            pen.Brush = New SolidColorBrush(BackedUpConfirmedUpChannelLineColor)
'                            pen.Thickness = 1
'                            channel.BCSwingLine.Pen = pen
'                            channel.IsBackedUp = True
'                        End If
'                    Next
'                    ShowLastConfirmedChannelLine(Direction.Up)
'                End If
'            End With
'        End Sub
'        Protected Sub ConfirmDownChannelLine(ByVal channelLine As ChannelLine)
'            For Each channel In channelLines
'                If channel.Direction = Direction.Down AndAlso channel.IsGapped AndAlso channel.IsConfirmed AndAlso channel.IsCut = False Then
'                    If channel.IsBackedUp Then
'                        channel.IsBackedUp = False
'                        AddChannelTrendlineToChart(channel.Base)
'                    End If
'                    Dim pen = channel.Base.Pen
'                    pen.Brush = New SolidColorBrush(GappedDownChannelLineColor)
'                    channel.Base.Pen = pen
'                    channel.Base.HasParallel = False
'                End If
'            Next
'            With channelLine
'                If .IsBackedUp Then
'                    .IsBackedUp = False
'                    AddChannelTrendlineToChart(.Base)
'                End If

'                .IsConfirmed = True
'                Dim value As Decimal = .CPoint.Y - .BPoint.Y
'                .TargetText = NewLabel("- " & FormatNumber(GetDollarValue(value), DecimalPlaces), ConfirmedDownChannelLineColor, New Point(CurrentBar.Number, CurrentSwing.EndPrice - value), BCTargetTextsVisible)
'                .TargetText.VerticalAlignment = LabelVerticalAlignment.Center
'                .BCSwingLine = NewTrendline(ConfirmedDownChannelLineColor, .BPoint, .CPoint, ChannelLinesVisible)
'                .BCSwingLine.Pen.Thickness = 2
'                RemoveObjectFromChart(.BCLengthText)
'                .BCLengthText = NewLabel(FormatNumber(GetDollarValue(value), DecimalPlaces, TriState.True), ConfirmedDownChannelLineColor, AddToX(.CPoint, -2), BCLengthTextsVisible)
'                .BCLengthText.HorizontalAlignment = LabelHorizontalAlignment.Right
'                .BCLengthText.VerticalAlignment = LabelVerticalAlignment.Bottom
'                Dim pen = .Base.Pen
'                pen.Brush = New SolidColorBrush(ConfirmedDownChannelLineColor)
'                pen.Thickness = 2
'                .Base.Pen = pen
'                RefreshObject(.Base)
'                If ShowOnlyLastConfirmedChannels Then
'                    For Each channel In channelLines
'                        If channel.IsConfirmed And channel.Direction = Direction.Down And Not channel.IsGapped And Not channel.IsCut Then
'                            pen = channel.Base.Pen
'                            pen.Brush = New SolidColorBrush(BackedUpConfirmedDownChannelLineColor)
'                            pen.Thickness = 1
'                            channel.Base.Pen = pen
'                            pen = channel.BCSwingLine.Pen
'                            pen.Brush = New SolidColorBrush(BackedUpConfirmedDownChannelLineColor)
'                            pen.Thickness = 1
'                            channel.BCSwingLine.Pen = pen
'                            channel.IsBackedUp = True
'                        End If
'                    Next
'                    ShowLastConfirmedChannelLine(Direction.Down)
'                End If
'            End With
'        End Sub

'        Protected Sub CheckDownChannelsCanExtend()
'            For Each channelLine In channelLines
'                If channelLine.Direction = Direction.Down AndAlso CurrentSwing.EndPrice >= channelLine.APoint.Y Then channelLine.CanExtend = False
'            Next
'        End Sub
'        Protected Sub CheckUpChannelsCanExtend()
'            For Each channelLine In channelLines
'                If channelLine.Direction = Direction.Up AndAlso CurrentSwing.EndPrice <= channelLine.APoint.Y Then channelLine.CanExtend = False
'            Next
'        End Sub

'        Protected Sub CheckChannelLinesForExtensions()
'            For Each channelLine In channelLines
'                With channelLine
'                    If .IsConfirmed Then
'                        If .CanExtend And ColorBars Then
'                            If .Direction = Direction.Up AndAlso CurrentSwing.Direction = Direction.Up AndAlso CurrentSwing.EndPrice >= .ExtendPrice Then
'                                BarColor(.APoint.X - 1, CurrentSwing.EndBar - 1, UpTrendBarColor, SwingLineUpTrendColor)
'                            ElseIf .Direction = Direction.Down AndAlso CurrentSwing.Direction = Direction.Down AndAlso CurrentSwing.EndPrice <= .ExtendPrice Then
'                                BarColor(.APoint.X - 1, CurrentSwing.EndBar - 1, DownTrendBarColor, SwingLineDownTrendColor)
'                            End If
'                        End If
'                        If .Direction = Direction.Up AndAlso CurrentSwing.EndPrice >= .ExtendPrice Then
'                            .ExtendPrice = CurrentSwing.EndPrice
'                            .TargetText.Location = New Point(CurrentBar.Number + 3, CurrentSwing.EndPrice - (.BPoint.Y - .CPoint.Y))
'                        ElseIf .Direction = Direction.Down AndAlso CurrentSwing.EndPrice <= .ExtendPrice Then
'                            .ExtendPrice = CurrentSwing.EndPrice
'                            .TargetText.Location = New Point(CurrentBar.Number + 3, CurrentSwing.EndPrice + (.CPoint.Y - .BPoint.Y))
'                        End If
'                    End If
'                End With
'            Next
'        End Sub
'        Protected Sub CheckChannelLinesForCancelOrConfirm()
'            For Each channelLine In channelLines
'                If Not channelLine.IsCancelled And Not channelLine.IsConfirmed And Not channelLine.IsCut Then
'                    If Not channelLine.IsConfirmed And channelLine.Direction = Direction.Up And CurrentSwing.EndPrice >= channelLine.PriceToConfirm Then
'                        'confirm up
'                        ShowLastPotentialChannelLine(Direction.Up)
'                        ConfirmUpChannelLine(channelLine)
'                    ElseIf channelLine.Direction = Direction.Up And CurrentSwing.EndPrice <= channelLine.PriceToCancel Then
'                        'cancel up
'                        If (channelLine.IsConfirmed Or CurrentSwing.EndPrice <= channelLine.APoint.Y) Then
'                            'Log("cancelled")
'                            'ShowLastConfirmedChannelLine(Direction.Up)
'                            'ShowLastPotentialChannelLine(Direction.Up)
'                            channelLine.IsCancelled = True
'                            If channelLine.PivotSwing Is CurrentSwing Or channelLine.CutBarNumber = -1 Then
'                                RemoveObjectFromChart(channelLine.Base)
'                            Else
'                                CutUpChannelLine(channelLine)
'                            End If
'                            channelLine.PivotSwing.ChannelLine = Nothing
'                        End If
'                        If channelLine.IsConfirmed = False Then RemoveObjectFromChart(channelLine.BCLengthText)
'                    ElseIf Not channelLine.IsConfirmed And channelLine.Direction = Direction.Down And CurrentSwing.EndPrice <= channelLine.PriceToConfirm Then
'                        'confirm down
'                        ShowLastPotentialChannelLine(Direction.Down)
'                        ConfirmDownChannelLine(channelLine)
'                    ElseIf channelLine.Direction = Direction.Down And CurrentSwing.EndPrice >= channelLine.PriceToCancel Then
'                        'cancel down
'                        If channelLine.IsConfirmed Or CurrentSwing.EndPrice >= channelLine.APoint.Y Then
'                            'ShowLastPotentialChannelLine(Direction.Down)
'                            'ShowLastConfirmedChannelLine(Direction.Down)
'                            channelLine.IsCancelled = True
'                            If channelLine.PivotSwing Is CurrentSwing Or channelLine.CutBarNumber = -1 Then
'                                RemoveObjectFromChart(channelLine.Base)
'                            Else
'                                CutDownChannelLine(channelLine)
'                            End If
'                            channelLine.PivotSwing.ChannelLine = Nothing
'                        End If
'                        If channelLine.IsConfirmed = False Then RemoveObjectFromChart(channelLine.BCLengthText)
'                    Else
'                        SetEndPoint(channelLine.Base, New Point(channelLine.PivotSwing.EndBar, channelLine.PivotSwing.EndPrice))
'                    End If
'                End If
'                'If Not swings.Contains(channelLine.PivotSwing) And channelLine.Base.HasParent Then
'                '    If RemoveTrendLineOnMerge Then RemoveObjectFromChart(channelLine.Base)
'                'End If
'            Next
'            Dim i As Integer
'            While i < channelLines.Count
'                If channelLines(i).IsCancelled Then
'                    channelLines.RemoveAt(i)
'                Else
'                    i += 1
'                End If
'            End While
'        End Sub

'        Private Sub ShowLastPotentialChannelLine(ByVal direction As Direction)
'            If ShowOnlyLastPotentialChannels Then
'                Dim lastBackupChannelLine As ChannelLine = Nothing
'                For Each channelLine In channelLines
'                    If channelLine.IsBackedUp And Not channelLine.IsConfirmed And channelLine.Direction = direction And Not channelLine.IsCut Then
'                        lastBackupChannelLine = channelLine
'                    End If
'                Next
'                If lastBackupChannelLine IsNot Nothing Then
'                    lastBackupChannelLine.IsBackedUp = False
'                    Dim pen = lastBackupChannelLine.Base.Pen
'                    pen.Brush = New SolidColorBrush(If(direction = AutoTrend.Direction.Down, PotentialDownChannelLineColor, PotentialUpChannelLineColor))
'                    lastBackupChannelLine.Base.Pen = pen
'                End If
'            End If
'        End Sub
'        Private Sub ShowLastConfirmedChannelLine(ByVal direction As Direction)
'            If ShowOnlyLastConfirmedChannels Then
'                Dim lastBackupChannelLine As ChannelLine = Nothing
'                Dim lastBar As Integer
'                For Each channelLine In channelLines
'                    If channelLine.IsBackedUp And channelLine.IsConfirmed And channelLine.Direction = direction And Not channelLine.IsCut And channelLine.Base.EndPoint.X > lastBar Then
'                        lastBar = channelLine.Base.EndPoint.X
'                        lastBackupChannelLine = channelLine
'                    End If
'                Next
'                If lastBackupChannelLine IsNot Nothing Then
'                    lastBackupChannelLine.IsBackedUp = False
'                    AddChannelTrendlineToChart(lastBackupChannelLine.Base)
'                    Dim pen = lastBackupChannelLine.Base.Pen
'                    pen.Brush = New SolidColorBrush(If(direction = AutoTrend.Direction.Down, ConfirmedDownChannelLineColor, ConfirmedUpChannelLineColor))
'                    pen.Thickness = 2
'                    pen = lastBackupChannelLine.BCSwingLine.Pen
'                    pen.Brush = New SolidColorBrush(If(direction = AutoTrend.Direction.Down, ConfirmedDownChannelLineColor, ConfirmedUpChannelLineColor))
'                    pen.Thickness = 2
'                    lastBackupChannelLine.Base.Pen = pen
'                End If
'            End If
'        End Sub
'        Protected Sub BarColor(ByVal startBar As Integer, ByVal endBar As Integer, ByVal color As Color, ByVal swingColor As Color)
'            For Each swing In swings
'                If swing.StartBar >= startBar And swing.EndBar <= endBar + 1 Then
'                    swing.TL.Pen.Brush = New SolidColorBrush(swingColor)
'                End If
'            Next
'            For i = startBar To endBar
'                If CType(Chart.bars(i).Pen.Brush, SolidColorBrush).Color <> color Then
'                    Chart.bars(i).Pen.Brush = New SolidColorBrush(color)
'                    RefreshObject(Chart.bars(i))
'                End If
'            Next
'        End Sub


'    End Class
'End Namespace
